import { deleteRightTodo, deleteRightItem, spliceGetDataTodo, getSaleNum, getValueArray, setEmptyArray, setArrayValue, setExchangeValue, spliceGetDataItem} from '@/views/sales/common/TableSaleMethods'
export default ({
  state: {
    saleData: '',
    GetsaleData: '',
    form: {
      name: '',
      date: [],
      gender: '1',
      commission: '',
      commissionCalculateTypeEnum: '1'
    }
  },
  mutations: {
    commissionSaleData (state,type) {
      let getdata = JSON.parse(JSON.stringify(state.saleData));
      getValueArray(getdata, {
          index: type,
          childName: "productSkuList",
          status: false
      });
      setEmptyArray(getdata, {
          index: type,
          childName: "productSkuList"
      });
      setArrayValue(getdata, {
          index: type,
          val1: false,
          childName: "productSkuList"
      });
      // debugger
      if(!state.GetsaleData.length) { //首次为空
          state.GetsaleData = getdata
      } else { // 防止每次更新的淹没其他的
          //把没有的第一层数据存在，GetsaleData里面
          //把没有的第二层的数据存在, GetsaleData里面
          spliceGetDataItem(getdata, state.GetsaleData)
          spliceGetDataTodo(getdata, state.GetsaleData)
      }
      if(type !== 'buttonChecked'){
          setExchangeValue(state.saleData, {index1: 'checked', index: 'buttonChecked',childName: 'productSkuList'})
      }
    },
    commissionSelectAll (state, param) {
      param
      ? setArrayValue(state.saleData, {
          index: "checked",
          val1: true,
          childName: "productSkuList"
        })
      : setArrayValue(state.saleData, {
          index: "checked",
          val1: false,
          childName: "productSkuList"
      });
    },
    setCommissionEmpty (state) {
      state.GetsaleData = ''
      state.saleData = ''
      state.form = {
        name: '',
        date: [],
        gender: '1',
        commission: '',
        commissionCalculateTypeEnum: '1'
      }
    },
    onChoiceCommissionType (state, that) {
      state.form.commissionCalculateTypeEnum == '1' ? that.commissionLength = 6 : that.commissionLength = 3 
    } 
  },
  getters: {
    getCommissionNum (state) {
      return getSaleNum(state.GetsaleData, {childName: 'productSkuList'})
    }
  },
})
